﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using outREACH.App_Code;

namespace outREACH
{
    public partial class MedicalForum : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                Label lbl1 = (Label)Master.FindControl("Label1");
                    lbl1.Text = "Welcome " + Session["Username"].ToString() + "!";
                    Label lbl2 = (Label)Master.FindControl("Name");
                    Users u = Users.GetName(Session["Username"].ToString());
                    lbl2.Text = u.firstName + " " + u.lastName;
                    Label lbl3 = (Label)Master.FindControl("Country");
                    lbl3.Text = Session["country"].ToString();
                    Button btn3 = (Button)Master.FindControl("Button4");
                    if (User.IsInRole("admin"))
                    {
                        btn3.Visible = true;
                    }
                }
        
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            if (User.IsInRole("admin"))
            {
                gvMedForumMain0.Visible = true;
                gvMedForumMain.Visible = false;

            }
        }
          
        

        protected void gvMedForumMain_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow row in gvMedForumMain.Rows)
            {
                HyperLink h2 = (HyperLink)row.FindControl("Hyperlink2");
                Label l2 = (Label)row.FindControl("Label3");
                string name = l2.Text;
                string title = h2.Text;
                List<MedForum> result = MedForum.GetMedForum();
                foreach (MedForum mf in result)
                {
                    if (name == mf.userName.ToString() && title == mf.title.ToString())
                    {
                        Session["MedForumID"] = mf.MedForumID;
                        Response.Redirect("~/Medical/MedicalForumView.aspx");
                    }
                }
            }
        }




        
    }
}